import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import permission from './modules/permission'
import tagsView from './modules/tagsView'

Vue.use(Vuex)
const store = new Vuex.Store({
  modules: {
    app,
    settings,
    user,
    permission,
    tagsView
  },
  getters,
  state: {
    showLoading: false,
    loadingCount: 0
  },

  mutations: {
    setShowLoading(state, data) {
      state.showLoading = data
    },
    setLoadingCount(state, data) {
      state.loadingCount += data
    }
  },
  actions: {
    addLoading(store) {
      if (store.state.loadingCount === 0) {
        store.commit('setShowLoading', true)
      }
      store.commit('setLoadingCount', 1)
    },
    isCloseLoading(store) {
      store.commit('setLoadingCount', -1)
      if (store.state.loadingCount === 0) {
        store.commit('setShowLoading', false)
      }
    }
  }

})

export default store
